package com.intelligentcar.springboot.service.serverImpl;

import com.intelligentcar.springboot.bean.Linelist;
import com.intelligentcar.springboot.bean.Scheduling;
import com.intelligentcar.springboot.bean.Vehicle;
import com.intelligentcar.springboot.mapper.SchedulingMapper;
import com.intelligentcar.springboot.service.SchedulingServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class SchedulingServerImpl implements SchedulingServer {
    @Autowired
    private SchedulingMapper schedulingMapper;

    @Override
    public List<Linelist> selectLine1() {
        return schedulingMapper.selectLine1();
    }

    @Override
    public List<Vehicle> selectVehicle(Scheduling scheduling) {
        return schedulingMapper.selectVehicle(scheduling);
    }

    @Override
    public List<Scheduling> selectTime(Scheduling scheduling) {
        String vehicleTime;
        List<Scheduling> list = new ArrayList<>();
        List<Scheduling> list1 = schedulingMapper.selectTime(scheduling);
        for (Scheduling s:list1) {
            Scheduling scheduling1 = new Scheduling();
            vehicleTime = s.getVehicleBeginTime() + "-" +  s.getVehicleEndTime();
            scheduling1.setVehicleTime(vehicleTime);
            list.add(scheduling1);
        }
        return list;
    }

    @Override
    public List<Scheduling> selectDrivername(Scheduling scheduling) {
        String time[] = scheduling.getVehicleTime().split("-");
        scheduling.setVehicleBeginTime(time[0]);
        return schedulingMapper.selectDrivername(scheduling);
    }

    @Override
    public int addScheduling(Scheduling scheduling) {
        String time =new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(new Date());
        scheduling.setAddTime(time);
        scheduling.setInTime("上午");
        String time1[] = scheduling.getVehicleTime().split("-");
        scheduling.setVehicleBeginTime(time1[0]);
        scheduling.setVehicleEndTime(time1[1]);
        return schedulingMapper.addScheduling(scheduling);
    }

    @Override
    public List<Scheduling> selectScheduling() {
        return schedulingMapper.selectScheduling();
    }
}
